# This is an API workspace, having public visibility by default makes perfect sense.
package(default_visibility = ["//visibility:public"])

##############################################################################
# Common
##############################################################################
load("@com_google_api_codegen//rules_gapic:gapic.bzl", "proto_library_with_info")

proto_library(
    name = "trace_proto",
    srcs = [
        "trace.proto",
        "tracing.proto",
    ],
    deps = [
        "//google/api:annotations_proto",
        "//google/rpc:status_proto",
        "@com_google_protobuf//:empty_proto",
        "@com_google_protobuf//:timestamp_proto",
        "@com_google_protobuf//:wrappers_proto",
    ],
)

proto_library_with_info(
    name = "trace_proto_with_info",
    deps = [":trace_proto"],
)

##############################################################################
# Java
##############################################################################
load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")
load(
    "@com_google_api_codegen//rules_gapic/java:java_gapic.bzl",
    "java_gapic_library",
    "java_resource_name_proto_library",
)
load("@com_google_api_codegen//rules_gapic/java:java_gapic_pkg.bzl", "java_gapic_assembly_gradle_pkg")

_JAVA_GRPC_DEPS = [
    "@com_google_api_grpc_proto_google_common_protos//jar",
]

java_proto_library(
    name = "trace_java_proto",
    deps = [":trace_proto"],
)

java_grpc_library(
    name = "trace_java_grpc",
    srcs = [":trace_proto"],
    deps = [":trace_java_proto"] + _JAVA_GRPC_DEPS,
)

java_resource_name_proto_library(
    name = "trace_resource_name_java_proto",
    gapic_yaml = "cloudtrace_gapic.yaml",
    deps = [":trace_proto"],
)

java_gapic_library(
    name = "trace_java_gapic",
    src = ":trace_proto_with_info",
    gapic_yaml = "cloudtrace_gapic.yaml",
    service_yaml = "//google/devtools/cloudtrace:cloudtrace_v2.yaml",
    test_deps = [":trace_java_grpc"],
    deps = [
        ":trace_java_proto",
        ":trace_resource_name_java_proto",
    ] + _JAVA_GRPC_DEPS,
)

[java_test(
    name = test_name,
    test_class = test_name,
    runtime_deps = [":trace_java_gapic_test"],
) for test_name in [
    "com.google.cloud.trace.v2.TraceServiceClientTest",
]]

# Opensource Packages
java_gapic_assembly_gradle_pkg(
    name = "google-cloud-trace-v2-java",
    client_deps = [":trace_java_gapic"],
    client_group = "com.google.cloud",
    client_test_deps = [":trace_java_gapic_test"],
    grpc_deps = [":trace_java_grpc"],
    grpc_group = "com.google.api.grpc",
    proto_deps = [
        ":trace_java_proto",
        ":trace_proto",
        ":trace_resource_name_java_proto",
    ] + _JAVA_GRPC_DEPS,
    version = "0.0.0-SNAPSHOT",
)

##############################################################################
# Go
##############################################################################
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@com_google_api_codegen//rules_gapic/go:go_gapic.bzl", "go_gapic_srcjar", "go_gapic_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@com_google_api_codegen//rules_gapic/go:go_gapic_pkg.bzl", "go_gapic_assembly_pkg")

go_proto_library(
    name = "trace_go_proto",
    compilers = ["@io_bazel_rules_go//proto:go_grpc"],
    importpath = "google.golang.org/genproto/googleapis/devtools/cloudtrace/v2",
    protos = [":trace_proto_with_info"],
    deps = [
        "//google/api:annotations_go_proto",
        "//google/rpc:status_go_proto",
    ],
)

go_gapic_library(
    name = "trace_go_gapic",
    src = ":trace_proto_with_info",
    gapic_yaml = "cloudtrace_gapic.yaml",
    importpath = "cloud.google.com/go/trace/apiv2",
    service_yaml = "//google/devtools/cloudtrace:cloudtrace_v2.yaml",
    deps = [":trace_go_proto"],
)

go_test(
    name = "trace_go_gapic_test",
    srcs = [":trace_go_gapic_srcjar_test"],
    embed = [":trace_go_gapic"],
    importpath = "cloud.google.com/go/trace/apiv2",
)

# Opensource Packages
go_gapic_assembly_pkg(
    name = "gapi-cloud-trace-v2-go",
    deps = [
        ":trace_go_gapic",
        ":trace_go_proto",
        ":trace_go_gapic_srcjar-smoke-test.srcjar",
        ":trace_go_gapic_srcjar-test.srcjar",
    ],
)